package com.swak.boot.config.metrics;

import static com.swak.boot.config.dubbo.DubboUtils.DUBBO_PREFIX;

import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.spring.beans.factory.annotation.ServiceClassPostProcessor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import com.codahale.metrics.MetricRegistry;
import com.swak.metrics.impl.CodahaleMetricsFactory;

/**
 * 指标暴露组件： Dubbo 方式： 不需要使用此方式, 保留此方式，供后续使用dubbo的一种借鉴
 * 
 * @author lifeng
 * @date 2021/04/14
 */
@Deprecated
@Configuration
@ComponentScan(value = { "com.swak.metrics.out.service" })
@ConditionalOnClass({ MetricRegistry.class, CodahaleMetricsFactory.class, DubboBootstrap.class })
@ConditionalOnProperty(prefix = DUBBO_PREFIX, name = "enabled", matchIfMissing = true)
public class AutoConfigurationMetricsDubboComponents {

	/**
	 * 直接扫码指定的目录来发布指定的指标
	 * 
	 * @return
	 */
	@Bean
	public MetricServiceAnnotationBeanPostProcessor dubboMetricServiceAnnotationBeanPostProcessor() {
		return new MetricServiceAnnotationBeanPostProcessor("com.swak.metrics.out.dubbo");
	}

	class MetricServiceAnnotationBeanPostProcessor extends ServiceClassPostProcessor {
		public MetricServiceAnnotationBeanPostProcessor(String... packagesToScan) {
			super(packagesToScan);
		}
	}
}